package br.com.sysprova.view;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JButton;

import br.com.sysprova.controller.DisciplinaController;
import br.com.sysprova.model.bean.Professor;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class PanelProfessor extends JPanel implements TreeSelectionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTree tree;
	private JPanel[] abas = new JPanel[2];
	private JTabbedPane tabbedPane;
	
	private Professor professor;
	

	/**
	 * Create the panel.
	 */
	public PanelProfessor(Object o) {
		setLayout(null);
			
		tree = new JTree();
		tree.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				//
			}
		});
		tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Professor") {
			{
				DefaultMutableTreeNode node_1;
				node_1 = new DefaultMutableTreeNode("Disciplinas");
				node_1.add(new DefaultMutableTreeNode("Redes 2"));
				node_1.add(new DefaultMutableTreeNode("Sistemas Operacionais"));
				add(node_1);
				node_1 = new DefaultMutableTreeNode("Provas");
				node_1.add(new DefaultMutableTreeNode("Redes 2"));
				add(node_1);
			}
		}));
		tree.setBounds(10, 11, 109, 372);
		tree.addTreeSelectionListener(this);
		tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		JScrollPane scrollPane = new JScrollPane(tree);
		scrollPane.setBounds(10, 11, 109, 372);
		add(scrollPane);
		
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(129, 11, 441, 372);
		add(tabbedPane);	
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("New tab", null, panel, null);
		
		JButton btnMudarTela = new JButton("Mudar Tela");
		panel.add(btnMudarTela);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("New tab", null, panel_1, null);
		
		JButton btnMudarOutraTela = new JButton("Mudar outra tela");
		btnMudarOutraTela.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.setSelectedIndex(0);
			}
		});
		panel_1.add(btnMudarOutraTela);

	}

	public PanelProfessor() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void valueChanged(TreeSelectionEvent arg0) {
		DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
				.getLastSelectedPathComponent();
		if (node == null)
			return;	
		
			
		String nome = (String) node.getUserObject();
		if (nome.equals("Disciplinas")){
			if (abas[0] == null) {
				abas[0] = new JPanel();
				Icon icone = new ImageIcon("imagens/disciplina.png");
				tabbedPane.addTab("Disciplinas", icone, abas[0], null);
			}else{
				//tabbedPane.
			}
			
		}
		
		if (nome.equals("Provas")){
			if (abas[1] == null) {
				abas[1] = new JPanel();
				Icon icone = new ImageIcon("imagens/prova.png");
				tabbedPane.addTab("Provas",  icone, abas[1], null);
			}else{
				
			}
		}
	}

	public Professor getProfessor() {
		return professor;
	}

	public void setProfessor(Professor professor) {
		this.professor = professor;
	}
}
